package utility;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.List;

public class NetUtils {

	private final static int IPV4_MAX_LENGTH = 15;

	public static List<String> getLocalIPAddresses() {

		List<String> s = null;
		InetAddress[] addresses;
		try {
			addresses = InetAddress.getAllByName(InetAddress.getLocalHost()
					.getHostName());
			s = new LinkedList<String>();
			for (int i = 0; i < addresses.length; i++) {
				int length = addresses[i].getHostAddress().length();
				if (length <= IPV4_MAX_LENGTH)
					s.add(addresses[i].getHostAddress());
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}
		return s;

	}
}
